package mest.service.Modeling.Impl;

import mest.dao.Modeling.IsaveTypeDao;
import mest.entity.save_file;
import mest.entity.save_type;
import mest.service.Modeling.IsaveTypeService;
import mest.util.ResultObj;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-16 0:36
 */
@Service
public class SaveTypeServiceImpl implements IsaveTypeService {

    @Resource
    private IsaveTypeDao istd;

    @Override
    public ResultObj insertsaveType(save_type st,String theirDb) {


        try {
            int i = istd.insertsaveType(st, theirDb);
            if (i > 0) {
                return  ResultObj.createSuccessMsg(ResultObj.INSERT_SUCCESS);
            }
        } catch (Exception e) {
            e.printStackTrace();
            if (e.getClass().getName().equals("org.springframework.dao.DuplicateKeyException")) {
                return ResultObj.createErrorMsg("编码重复");
            }
            return ResultObj.createErrorMsg(ResultObj.ERROR);
        }
        return ResultObj.createErrorMsg(ResultObj.ERROR);
    }


    @Override
    public int selectCount(String theirDb) {
        return istd.selectCount(theirDb);
    }

    @Override
    public List<save_type> findSaveTypePage(int index, int pageSize,String theirDb) {
        return istd.findSaveTypePage((index-1)*pageSize,pageSize, theirDb);
    }

    @Override
    public int delModel(Integer id,String theirDb) {
        return istd.delModel(id,theirDb);
    }

    @Override
    public List<save_type> queryAll(Integer index, Integer pageSize, String record,String theirDb) {
        return istd.queryAll((index-1)*pageSize,pageSize, record, theirDb);
    }

    @Override
    public int findCount(String record,String theirDb) {
        return istd.findCount(record, theirDb);
    }

    @Override
    public int updateByOne(save_type record,String theirDb) {
        return istd.updateByPrimaryKeySelective(record, theirDb);
    }
}
